#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>

int mybus_match(struct device *dev, struct device_driver *drv)
{
	//如果匹配成功,match方法一定要返回1, 失败返回0
	//匹配成功会调用mydrv.c中mydrv_probe函数
	
	printk("---------------%s--------------\n", __FUNCTION__);

	if(!strncmp(drv->name, dev->kobj.name, sizeof(drv->name)))
	{
		printk("mybus_match----match ok\n");
		return 1;
	}else
	{
		printk("mybus_match----match failed\n");
		return 0;
	}

	return 0;
}

//实例化一个bus对象
struct bus_type mybus = {
	.name = "mybus",
	.match = mybus_match
};

EXPORT_SYMBOL(mybus);



static int __init mybus_init(void)
{
	int ret;
	printk("---------------%s--------------\n", __FUNCTION__);

	//构建一个总线        sys/bus/mybus
	ret = bus_register(&mybus);
	if(ret != 0)
	{
		printk("bus_register error\n");
		return ret;
	}

	return 0;
}

static void __exit mybus_exit(void)
{
	printk("---------------%s--------------\n", __FUNCTION__);
	bus_unregister(&mybus);
}


module_init(mybus_init);
module_exit(mybus_exit);
MODULE_LICENSE("GPL");

